package com.fico.blaze.service;

import com.blazesoft.server.base.NdServerException;
import com.blazesoft.server.base.NdServerRuntimeException;
import com.blazesoft.server.deploy.webservice.NdWebServiceDeploymentBase;
import com.blazesoft.server.local.NdLocalServerException;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(
        portName = "RuleServicePort",
        serviceName = "RuleServiceService",
        targetNamespace = "http://service.blaze.fico.com")
public class RuleService extends NdWebServiceDeploymentBase
{

    public RuleService()
    {
        super();
    }

    /**
     *	invokes a server process based on the entry point "invokeExternalMain"
     *	in the service "EDMRuleService" configured in the Quick Deployer.
     *
     *	@param	arg0		==>Enter a description here
     *	@return	String	==>Enter a description of the return value
     */
    @WebMethod
    public String invokeExternalMain(String arg0) throws Exception
    {
        // Convert the business method arguments to rules processing arguments.
        Object[] applicationArgs = new Object[1];
        applicationArgs[0] = arg0;


        // Invoke the entry point
        String retVal = (String)getDelegateServer().invokeService("RuleService", "invokeExternalMain", null, applicationArgs);

        return retVal;
    }
    /**
     *	invokes a server process based on the entry point "invokeExternalMainArray"
     *	in the service "EDMRuleService" configured in the Quick Deployer.
     *
     *	@param	arg0		==>Enter a description here
     *	@return	java.util.Vector	==>Enter a description of the return value
     */
    @WebMethod
    public java.util.Vector invokeExternalMainArray(java.util.Vector arg0) throws Exception
    {
        // Convert the business method arguments to rules processing arguments.
        Object[] applicationArgs = new Object[1];
        applicationArgs[0] = arg0;


        // Invoke the entry point
        java.util.Vector retVal = (java.util.Vector)getDelegateServer().invokeService("RuleService", "invokeExternalMainArray", null, applicationArgs);

        return retVal;
    }

    @WebMethod
    public boolean restart(){
        try {
            getDelegateServer().resetService("RuleService");
            return true;
        } catch (NdLocalServerException e) {
            e.printStackTrace();
            return false;
        }
    }

    @PostConstruct
    private void init()
    {
        try {
            super.initialize();
        }
        catch (NdServerException e) {
            throw new NdServerRuntimeException(e);
        }
    }

    @PreDestroy
    private void destroy()
    {
        try {
            super.shutdown();
        }
        catch (NdServerException e) {
            throw new NdServerRuntimeException(e);
        }
    }

}


